package com.ruoyi.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.Shopkeeper;
import com.ruoyi.shop.service.IShopkeeperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家管理Controller
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@Anonymous
@RestController
@RequestMapping("/shop/shopkeeper")
public class ShopkeeperController extends BaseController
{
    @Autowired
    private IShopkeeperService shopkeeperService;

    /**
     * 查询商家管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Shopkeeper shopkeeper)
    {
        startPage();
        List<Shopkeeper> list = shopkeeperService.selectShopkeeperList(shopkeeper);
        return getDataTable(list);
    }
    @GetMapping("/list1")
    public TableDataInfo list1(Shopkeeper shopkeeper)
    {
        startPage();
        List<Shopkeeper> list = shopkeeperService.selectShopkeeperGoodsList(shopkeeper);
        return getDataTable(list);
    }
    @GetMapping("/list2")
    public TableDataInfo list2(Shopkeeper shopkeeper)
    {
        startPage();
        List<Shopkeeper> list = shopkeeperService.selectShopkeeperWithCategories(shopkeeper);
        return getDataTable(list);
    }
    /**
     * 导出商家管理列表
     */
    @Log(title = "商家管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shopkeeper shopkeeper)
    {
        List<Shopkeeper> list = shopkeeperService.selectShopkeeperList(shopkeeper);
        ExcelUtil<Shopkeeper> util = new ExcelUtil<Shopkeeper>(Shopkeeper.class);
        util.exportExcel(response, list, "商家管理数据");
    }

    /**
     * 获取商家管理详细信息
     */
    @GetMapping(value = "/{shopid}")
    public AjaxResult getInfo(@PathVariable("shopid") Long shopid)
    {
        return AjaxResult.success(shopkeeperService.selectShopkeeperByShopid(shopid));
    }

    /**
     * 新增商家管理
     */
    @Log(title = "商家管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shopkeeper shopkeeper)
    {
        return toAjax(shopkeeperService.insertShopkeeper(shopkeeper));
    }

    /**
     * 修改商家管理
     */
    @Log(title = "商家管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shopkeeper shopkeeper)
    {
        return toAjax(shopkeeperService.updateShopkeeper(shopkeeper));
    }

    /**
     * 删除商家管理
     */
    @Log(title = "商家管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shopids}")
    public AjaxResult remove(@PathVariable Long[] shopids)
    {
        return toAjax(shopkeeperService.deleteShopkeeperByShopids(shopids));
    }
}
